package com.ghn.cocknovel.ui.activity.work.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.example.basemodel.base.BaseViewModel
import com.ghn.cocknovel.net.DataService
import com.kt.NetworkModel.bean.ResultListBean
import com.kt.NetworkModel.bean.ToDayWorkTaskBean
import com.kt.NetworkModel.bean.queryDriverTransitOrderListBean
import com.kt.NetworkModel.net.CallBack
import com.kt.NetworkModel.net.RxUtils

/**
 *@author: Administrator
 *2023/10/15
 *desc:
 */
class ToDayWorkTaskViewModel(application: Application) : BaseViewModel(application) {

    var currentPage = 1
    val mToDayWorkTaskBeanLiveData = MutableLiveData<ResultListBean<ToDayWorkTaskBean>>()
    val mOverSubmitLiveData = MutableLiveData<String>()
    val mCloseTaskLiveData = MutableLiveData<Boolean>()

    fun driverQueryTransitSchedulePlanListNet() {
        DataService.driverQueryTransitSchedulePlanList(currentPage).compose(RxUtils.mainSync()).subscribe(object : CallBack<ResultListBean<ToDayWorkTaskBean>>() {
            override fun onResult(result: ResultListBean<ToDayWorkTaskBean>?) {
                result?.also {
                    mToDayWorkTaskBeanLiveData.value = it
                }
            }
        })
    }

    /**
     * 司机确认开始任务
     */
    fun confirmTransitSchedulePlanNet(taskId: String, carLongitude: String, carLatitude: String) {
        DataService.confirmTransitSchedulePlan(taskId, carLongitude, carLatitude, "").compose(RxUtils.mainSync()).subscribe(object : CallBack<String>() {
            override fun onResult(result: String?) {
                mOverSubmitLiveData.value = ""
            }

            override fun onError(e: String, code: Int): Boolean {
                mOverSubmitLiveData.value = e
                return super.onError(e, code)
            }
        })
    }

    /**
     * 司机确认结束任务
     */
    fun finishTransitSchedulePlanNet(taskId: String, carLongitude: String, carLatitude: String) {
        DataService.finishTransitSchedulePlanNet(taskId, carLongitude, carLatitude).compose(RxUtils.mainSync()).subscribe(object : CallBack<String>() {
            override fun onResult(result: String?) {
                mOverSubmitLiveData.value = ""
            }
        })
    }

    /**
     * 司机确认取消任务
     */
    fun cancelTransitSchedulePlanNet(taskId: String) {
        DataService.cancelTransitSchedulePlanNet(taskId).compose(RxUtils.mainSync()).subscribe(object : CallBack<String>() {
            override fun onResult(result: String?) {
                mCloseTaskLiveData.value = true
            }
        })
    }

}